//
//  StatusBottomView.swift
//  sinaweiboFirst
//
//  Created by mac on 16/3/12.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

/*三等分视图: 
1.平铺所有视图
2.最右边和最左边视图 分别添加相对父视图约束
3.设置等宽
*/

class StatusBottomView: UIView {
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: 按钮的监听事件
     @objc private func repostBtnDidClick() {
        //页面跳转
        let temp = TempViewController()
        
        //隐藏底部的tabBar 
        temp.hidesBottomBarWhenPushed = true
        
        //使用导航视图控制 跳转页面
        navController()?.pushViewController(temp, animated: true)
    }

    //MARK: 设置UI界面
    private func setupUI() {

//        backgroundColor = UIColor(white: 0.9, alpha: 1)
        backgroundColor = UIColor.yellowColor()
        
        addSubview(repostBtn)
        addSubview(commentBtn)
        addSubview(goodBtn)
        //设置约束 三个按钮平分视图
        repostBtn.snp_makeConstraints { (make) -> Void in
            make.top.bottom.left.equalTo(self)
        }
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.left.equalTo(repostBtn.snp_right)
            make.width.equalTo(repostBtn.snp_width)
        }
        goodBtn.snp_makeConstraints { (make) -> Void in
            make.top.bottom.right.equalTo(self)
            make.left.equalTo(commentBtn.snp_right)
            make.width.equalTo(commentBtn.snp_width)
        }
        
        let sepLine1 = sepView()
        
        let sepLine2 = sepView()
        
        addSubview(sepLine1)
        addSubview(sepLine2)
        
        let w: CGFloat = 0.3
        
        sepLine1.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(repostBtn.snp_right)
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.centerY.equalTo(self.snp_centerY)
            make.width.equalTo(w)
        }
        sepLine2.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(commentBtn.snp_right)
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.centerY.equalTo(self.snp_centerY)
            make.width.equalTo(w)
        }
        
        //添加按钮的监听事件
        repostBtn.addTarget(self, action: "repostBtnDidClick", forControlEvents: .TouchUpInside)
    
    }
    
    
    
    //懒加载子视图
    private lazy var repostBtn: UIButton = UIFactory.buttonWithTitle("转发", backImageName: nil, textColor: UIColor.darkGrayColor(), fontSize: 12, imageName: "timeline_icon_retweet")
    private lazy var commentBtn: UIButton = UIFactory.buttonWithTitle("评论", backImageName: nil, textColor: UIColor.darkGrayColor(), fontSize: 12, imageName: "timeline_icon_comment")
    private lazy var goodBtn: UIButton = UIFactory.buttonWithTitle("点赞", backImageName: nil, textColor: UIColor.darkGrayColor(), fontSize: 12, imageName: "timeline_icon_unlike")
    
    //分割线视图
    private func sepView() -> UIView {
    
        let lineView = UIView()
        lineView.backgroundColor = UIColor.lightGrayColor()
        return lineView
    }
    
}
